let today = new Date();
let today_year_month_day = `${today.getFullYear()}` + `-` + `${today.getMonth()+1}`.padStart(2, '0') + `-` +
	`${today.getDate()}`.padStart(2, '0');
let tomorrow = new Date(today.getTime() + (24 * 60 * 60 * 1000 * 1)); //明天
let tomorrow_year_month_day = `${tomorrow.getFullYear()}` + `-` + `${tomorrow.getMonth()+1}`.padStart(2, '0') + `-` +
	`${tomorrow.getDate()}`.padStart(2, '0');

import {
		session_info
} from '@/common/api.js';
	
export default {
	data() {
		return {
			today_year_month_day:today_year_month_day,
			tomorrow_year_month_day:tomorrow_year_month_day
		}
	},
	filters: {
		formatPrice(price) {
			price = '' + price;
			price = price
				.replace(/\s*/g, "") //去除字符串内所有的空格
				.replace(/[^\-\d.]/g, '') // 清除“-”“数字”和“.”以外的字符
				.replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
				.replace('.', '$#$')
				.replace(/\./g, '')
				.replace('$#$', '.')
				.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); // 只能输入两个小数
			// if (price.indexOf('.') < 0 && price != '') {
			//     // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
			//     price = parseFloat(price);
			// }
			// if (price[0] == '0' && price != '') {
			//     // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
			//     price = parseFloat(price);
			// }
			if (price != '') {
				price = Number(price);
			}
			return price;
		},
		filterDate(value) {
			let _Date = new Date(value);
			let _year = _Date.getFullYear();
			let _month = _Date.getMonth() + 1;
			let _day = _Date.getDate();
			if (_day < 10) {
				_day = '0' + _day;
			}
			// return _month + '月'+_day+'日';
			return _day;
		}
	},
	methods: {
		upx2px(num){
			return uni.upx2px(num)
		},
		isVirtualId(id) {
			if ((id + '').startsWith('virtual')) {
				return true
			} else {
				return false;
			}
		},
		momentTZ(dateStr, format) {
			if (!dateStr) {
				return ''
			}
			if (!format) {
				format = 'YYYY-MM-DD HH:mm:ss';
			}
			// console.log(this.$moment.tz.guess());
			let new_dateStr = this.$momentTZ(dateStr).tz("Asia/Shanghai").format(format);
			return new_dateStr
		},
		formatPrice(price) {
			price = '' + price;
			price = price
				.replace(/\s*/g, "") //去除字符串内所有的空格
				.replace(/[^\-\d.]/g, '') // 清除“-”“数字”和“.”以外的字符
				.replace(/\.{2,}/g, '.') // 只保留第一个. 清除多余的
				.replace('.', '$#$')
				.replace(/\./g, '')
				.replace('$#$', '.')
				.replace(/^(\-)*(\d+)\.(\d\d).*$/, '$1$2.$3'); // 只能输入两个小数
			// if (price.indexOf('.') < 0 && price != '') {
			//     // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
			//     price = parseFloat(price);
			// }
			// if (price[0] == '0' && price != '') {
			//     // 以上已经过滤，此处控制的是如果没有小数点，首位不能为类似于 01、02的金额
			//     price = parseFloat(price);
			// }
			if (price != '') {
				price = Number(price);
			}
			return price;
		},
		isToday(y_m_d) {
			let _Date = new Date(y_m_d);
			let _year = _Date.getFullYear();
			let _month = _Date.getMonth();
			let _day = _Date.getDate();

			let _Today = new Date();
			let _Today_year = _Today.getFullYear();
			let _Today_month = _Today.getMonth();
			let _Today_day = _Today.getDate();

			if (_year == _Today_year && _month == _Today_month && _day == _Today_day) {
				return true;
			} else {
				return false;
			}
		},
		make_add_function() {
			let id = 1;
			return () => {
				return `virtual${id++}`;
			}
		},
		// 图片线上路径
		getImgSrc(src) {
			let baseUrl = 'https://www.jialigui.com/attachment/images1/';
			return baseUrl + src;
		},
		// 富文本样式
		parseTagStyle() {
			return {
				'ul': 'padding-left:0;list-style:none;margin-left:0;margin-right:0',
				'ol': 'padding-left:0;list-style:none;margin-left:0;margin-right:0'
			}
		},
		// 跳转
		nav(url, type) {
			try {
				uni.$u.route({
					url: url,
					type: type || 'navigateTo'
				})
			} catch (e) {
				console.log(e);
			}
		},
		// 是否登录跳转
		navLogin(url, type) {
			if (this.$store.getters.get_isLogin) {
				this.nav(url, type);
			} else {
				uni.reLaunch({
					url: '/pages/my/my'
				});
			}
		},
		// 下载文件并打开
		openFile(url) {
			uni.downloadFile({
				url: url,
				// url: '/attachment/images/1/2022/06/uRzd1I11EPoELer1YG6451aO1YL5EA.docx',
				success: function(res) {
					var filePath = res.tempFilePath;
					uni.openDocument({
						filePath: filePath,
						showMenu: true,
						success: function(res) {
							console.log('打开文档成功');
						}
					});
				}
			});
		},
		getStatusBarHeight() {
			const res = uni.getSystemInfoSync();
			if (res.platform === 'ios') {
				return 44 + res.statusBarHeight;
			} else if (res.platform === 'android') {
				return 48 + res.statusBarHeight;
			} else {
				return 0;
			}
		},
		//获取可视区域高度
		getClineHeight() {
			const res = uni.getSystemInfoSync();
			let clientHeight = res.windowHeight;
			return clientHeight;
			// const res = uni.getSystemInfo({
			// 	success: (res => {
			// 		 // - uni.upx2px(80)
			// 		this.clientHeight = res.windowHeight - this.getBarHeight();
			// 		console.log(res);
			// 		console.log(this.clientHeight);
			// 	})
			// });
		},
		toObj(data,key){
			let obj = {};
			data.forEach(v=>{
				obj[v[key]] = v;
			});
			return obj;	
		},
		async get_session_info(){
			await session_info().then((res) => {
				this.$store.commit('set_sessionInfo',res);
			}).catch(() => {
				throw 'session_info 失败';
			}).finally(() => {
				
			})
		},
	}
}